package Item

import (
	"../ProtoGo"
	"../Robot"
	"github.com/golang/protobuf/proto"
)

var command = Cmd.Command_SCENE_USER_ITEM_PROTOCMD.Enum()

func RegisterItemHandler(r *Robot.Robot) {
	r.RobotLog("注册道具模块")

	pp := Cmd.ItemParam_ITEMPARAM_PACKSLOTNTF.Enum()
	r.Handler.RegisterHandle(byte(*command), byte(*pp), handlePackSlotNtfItemCmd)

	pp = Cmd.ItemParam_ITEMPARAM_NTF_HIGHTREFINE_DATA.Enum()
	r.Handler.RegisterHandle(byte(*command), byte(*pp), handleNtfHighRefineDataCmd)
}

func handlePackSlotNtfItemCmd(xcmd *Robot.XCommand, robot *Robot.Robot) {
	response := &Cmd.PackSlotNtfItemCmd{}
	if err := proto.Unmarshal(xcmd.Probuf, response); err != nil {
		robot.RobotErr("序列化PackSlotNtfItemCmd")
	} else {
		robot.RobotLog("接收协议PackSlotNtfItemCmd %s ", response.String())
	}
}

func handleNtfHighRefineDataCmd(xcmd *Robot.XCommand, robot *Robot.Robot) {
	response := &Cmd.NtfHighRefineDataCmd{}
	if err := proto.Unmarshal(xcmd.Probuf, response); err != nil {
		robot.RobotErr("序列化NtfHighRefineDataCmd")
	} else {
		robot.RobotLog("接收协议NtfHighRefineDataCmd %s ", response.String())
	}
}
